﻿using System;
using System.Drawing;

namespace CloudShot.Editor
{
  internal class AutomaticCanvasRefresher : IDisposable
  {
    private readonly IDrawingCanvas _canvas;
    private readonly Func<Rectangle> _getBoundsFunc;
    private Rectangle _clipRectangle;

    public AutomaticCanvasRefresher(IDrawingCanvas canvas, Func<Rectangle> getBoundsFunc)
    {
      _canvas = canvas;
      _getBoundsFunc = getBoundsFunc;
      
      _clipRectangle = getBoundsFunc();
    }

    public void Dispose()
    {
      _clipRectangle = Rectangle.Union(_getBoundsFunc(), _clipRectangle);
      _canvas.RefreshCanvas(_clipRectangle);
    }
  }
}
